/**
 * 商家信息管理初始化
 */
var BusinessCompany = {
    id: "BusinessCompanyTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
BusinessCompany.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '大类名称', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '商家名称', field: 'name', visible: true, align: 'center', valign: 'middle'},
            {title: '联系方式', field: 'phone', visible: true, align: 'center', valign: 'middle'},
            {title: '所在位置', field: 'place', visible: true, align: 'center', valign: 'middle'},
            {title: '联系人', field: 'contacts', visible: true, align: 'center', valign: 'middle'},
            {title: '大类缩写', field: 'cateId', visible: true, align: 'center', valign: 'middle'},
            {title: '大类别结构的版本', field: 'version', visible: true, align: 'center', valign: 'middle'},
            {title: '扩展属性（用json来表示）', field: 'ext', visible: true, align: 'center', valign: 'middle'},
            {title: '是否有效', field: 'isValid', visible: true, align: 'center', valign: 'middle'},
            {title: '备注', field: 'remark', visible: true, align: 'center', valign: 'middle'},
            {title: '创建人', field: 'createUser', visible: true, align: 'center', valign: 'middle'},
            {title: '', field: 'createTime', visible: true, align: 'center', valign: 'middle'},
            {title: '', field: 'updateUser', visible: true, align: 'center', valign: 'middle'},
            {title: '', field: 'updateTime', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
BusinessCompany.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        BusinessCompany.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加商家信息
 */
BusinessCompany.openAddBusinessCompany = function () {
    var index = layer.open({
        type: 2,
        title: '添加商家信息',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/businessCompany/businessCompany_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看商家信息详情
 */
BusinessCompany.openBusinessCompanyDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '商家信息详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/businessCompany/businessCompany_update/' + BusinessCompany.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除商家信息
 */
BusinessCompany.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/businessCompany/delete", function (data) {
            Feng.success("删除成功!");
            BusinessCompany.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("businessCompanyId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询商家信息列表
 */
BusinessCompany.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    BusinessCompany.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = BusinessCompany.initColumn();
    var table = new BSTable(BusinessCompany.id, "/businessCompany/list", defaultColunms);
    table.setPaginationType("client");
    BusinessCompany.table = table.init();
});
